home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / STCLR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  1.0 KB  |  34 lines

  1. #include <graphics.h>
  2. #include <stdlib.h>
  3.  
  4. main()
  5. {
  6.    int graphdriver = DETECT, graphmode;
  7.    int maxcolor, color;
  8.    char buffer[80];
  9.  
  10. /* Initialize the graphics system */
  11.    initgraph(&graphdriver, &graphmode, "c:\\turboc");
  12. /* Now keep switching background colors randomly */
  13.    maxcolor = getmaxcolor();
  14. /* Initialize random number generator */
  15.    randomize();
  16.    outtextxy(10,20, "Demonstrating setcolor");
  17.    outtextxy(10,30, "Press any key to exit");
  18.    while (!kbhit())
  19.    {
  20.        color = random(maxcolor);
  21.        setcolor(color);
  22.        rectangle(50,50, 150,90);
  23.        sprintf(buffer, "Color number %2d", color);
  24.    /* Erase the area where color number will be shown */
  25.        setfillstyle(EMPTY_FILL, color);
  26.        bar(50,100, 50+textwidth(buffer), 100+2*textheight(buffer));
  27.        setcolor(WHITE);
  28.        outtextxy(50,100+textheight("H"), buffer);
  29.        delay(1000);  /* Pause for 1 second */
  30.    /* Wait for 1 second, then exit */
  31.        delay(1000);
  32.        closegraph();
  33.    }
  34. }